#ifndef G3_FONT_H
#define G3_FONT_H

#include "log.h"

#include "res_handle.h"
#include "res_texture.h"
#include "res_texture_mgr.h"

#include "types.h"
#include "math/m_vector.h"
#include "tex/tex_bitmap.h"
#include "projection.h"

#include "../lua_font.h"

namespace G3 {

class FONT {
	public:
		FONT ();
		~FONT ();

		LOG *Log;

		int Base;

		int NumChars;
		int NumCharsPerRow;
		int NumCharStart;
		int Width;
		int Height;

		int CharSet;

		float Spacing;

		H_TEXTURE Texture;

//==============================================================================
// Builds a font from OpenGL texture
//==============================================================================
		bool glBuildFromTexture (H_TEXTURE Tex);

//==============================================================================
// Calculates the width of the text in pixels
//==============================================================================
		int CalcTextWidth (const string &Text);

//==============================================================================
// Clips the text to a length in pixels
//==============================================================================
		string ClipTextRight (const string &aText, int aLength);
		string ClipTextLeft (const string &aText, int aLength);

//==============================================================================
// Draws a text buffer using this font
//==============================================================================
		void DrawTextBuffer (const string &Buffer);

//==============================================================================
// Loads a font from the stream
//==============================================================================
		bool Load (STREAM *aStream);

//==============================================================================
// Loads a font by its script filename
//==============================================================================
		bool Load (const char *aFilename);

//==============================================================================
// Checks if the font has been successfully built
//==============================================================================
		bool IsBuilt ();

//==============================================================================
// Dumps the font into the log
//==============================================================================
		void Dump (G3::LOG *aLog);

//==============================================================================
// Clears the Font
//==============================================================================
		void Clear ();
};

class TEXTBOX {
	public:
		TEXTBOX (FONT *fnt = NULL);

		FONT *Font;

		COL3F Color;
		VEC2I Position;

//==============================================================================
// Prints something into the textbox with Font
//==============================================================================
		bool glPrint (const char *fmt, ...);
};

typedef G3::HANDLE<G3::FONT> 	FONT_H;

}

#endif

